 var counter = 0;
 
 var message="Sorry, right-click has been disabled";
 

function clickIE() {
           if (document.all) {
                      (message);
           return false;
           }
}

function clickNS(e) {
           if (document.layers||(document.getElementById&&!document.all)) { 
                      if (e.which==2||e.which==3) {
                                 (message);return false;
                      }
           }
} 

 //Format Nilai Uang
 function number_format(a, b, c, d) {
            a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
            e = a + '';
            f = e.split('.');
            if (!f[0]) {
            f[0] = '0';
            }
            if (!f[1]) {
            f[1] = '';
            }
            if (f[1].length < b) {
            g = f[1];
            for (i=f[1].length + 1; i <= b; i++) {
            g += '0';
            }
            f[1] = g;
            }
            if(d != '' && f[0].length > 3) {
            h = f[0];
            f[0] = '';
            for(j = 3; j < h.length; j+=3) {
            i = h.slice(h.length - j,h.length - j + 3);
            f[0] = d + i +  f[0] + '';
            }
            j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
            f[0] = j + f[0];
            }
            c = (b <= 0) ? '' : c;
            return f[0] + c + f[1]; 
}
    
//Menghitung Umur dari tanggal ditentukan    

function hitungUmur(){
        var tanggal=$('#tglLahir').attr('value');
        var elem = tanggal.split('/');
        var tahun = elem[2];
        var bulan = elem[1];
        var hari  = elem[0];
        if((tahun==0 && bulan==0 && tahun==0)|| tanggal==null || tanggal==''){
            $('#umur-tahun').attr('value',0);
            $('#umur-bulan').attr('value',0);
            $('#umur-hari').attr('value',0);
            return false;
        }
        var now=new Date();
        var day =now.getUTCDate();
        var month =now.getUTCMonth()+1;
        var year =now.getYear()+1900;
        
        tahun=year-tahun;
        bulan=month-bulan;
        hari=day-hari;
        
        var jumlahHari;
        var bulanTemp=(month==1)?12:month-1;
        if(bulanTemp==1 || bulanTemp==3 || bulanTemp==5 || bulanTemp==7 || bulanTemp==8 || bulanTemp==10 || bulanTemp==12){
            jumlahHari=31;
        }else if(bulanTemp==2){
            if(tahun % 4==0)
                jumlahHari=29;
            else
                jumlahHari=28;
        }else{
            jumlahHari=30;
        }

        if(hari<=0){
            hari+=jumlahHari;
            bulan--;
        }
        if(bulan<0 || (bulan==0 && tahun!=0)){
            bulan+=12;
            tahun--;
        }
        $('#umur-tahun').attr('value',tahun);
        $('#umur-bulan').attr('value',bulan);
        $('#umur-hari').attr('value',hari);
}

function Angka(obj) {
        a = obj.value;
        b = a.replace(/[^\d]/g,'');
        c = '';
        lengthchar = b.length;
        j = 0;
        for (i = lengthchar; i > 0; i--) {
                j = j + 1;
                if (((j % 3) == 1) && (j != 1)) {
                        c = b.substr(i-1,1) + '' + c;
                } else {
                        c = b.substr(i-1,1) + c;
                }
        }
        obj.value = c;
}

function FormNum(obj) {
        a = obj.value;
        b = a.replace(/[^\d]/g,'');
        c = '';
        lengthchar = b.length;
        j = 0;
        for (i = lengthchar; i > 0; i--) {
                j = j + 1;
                if (((j % 3) == 1) && (j != 1)) {
                        c = b.substr(i-1,1) + '.' + c;
                } else {
                        c = b.substr(i-1,1) + c;
                }
        }
        obj.value = c;
}

function Desimal(obj){
    a=obj.value;    
    b=a.match(/[0-9]+(?:\.[0-9]{0,2})?/g,'');
    if(b==null){
        obj.value='';
    }else{
        obj.value=b[0];
    }
    
}

function rata2(number){
    var a = number.split('.');
    var numb1 = a[0];
    var numb2 = a[1].substr(0,2);
    
    return numb1+','+numb2;
}
function numberToCurrency(a){
    a=a.toString();
    var b = a.replace(/[^\d]/g,'');
    var c = '';
    var lengthchar = b.length;
    var j = 0;
    for (var i = lengthchar; i > 0; i--) {
	    j = j + 1;
	    if (((j % 3) == 1) && (j != 1)) {
		    c = b.substr(i-1,1) + '.' + c;
	    } else {
		    c = b.substr(i-1,1) + c;
	    }
    }
    return c;
}

function currencyToNumber(a){
    a+='';
    return parseInt(a.replace(/\.+/g, ''));
}

function formatNumber(obj) {
	var a = obj.value;
	obj.value = numberToCurrency(a);
}

function removeHtmlTag(strx){
	if(strx.indexOf("<")!=-1) {
		var s = strx.split("<");
		for(var i=0;i<s.length;i++){
		if(s[i].indexOf(">")!=-1){
			s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length);
		}
	}
	strx = s.join(" ");
	}
	return strx;
}

/*
if (document.layers) {
           document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
} else {
           document.onmouseup=clickNS;document.oncontextmenu=clickIE;
}

document.oncontextmenu=new Function("return false")    
*/ 
$(function() {
	//Aksi DOM umur
	$('#umur-hari, #umur-bulan, #umur-tahun').blur(function(){
	    if($('#umur-hari').attr('value')==0) $('#umur-hari').attr('value', '0');
	    if($('#umur-bulan').attr('value')==0) $('#umur-bulan').attr('value', '0');
	    if($('#umur-tahun').attr('value')==0) $('#umur-tahun').attr('value', '0');
	    var now=new Date();
	    var hari =now.getUTCDate()-$('#umur-hari').attr('value');
	    var bulan =now.getUTCMonth()+1-$('#umur-bulan').attr('value');
	    var tahun =now.getYear()-$('#umur-tahun').attr('value')+1900;
	    if(hari==null) hari=0;
	    if(bulan==null) bulan=0;
	    if(tahun==null) tahun=0;
	    var jumlahHari;
	    var bulanTemp=(bulan==1)?12:bulan-1;
	    if(bulanTemp==1 || bulanTemp==3 || bulanTemp==5 || bulanTemp==7 || bulanTemp==8 || bulanTemp==10 || bulanTemp==12){
		jumlahHari=31;
	    }else if(bulanTemp==2){
		if(tahun % 4==0)
		    jumlahHari=29;
		else
		    jumlahHari=28;
	    }else{
		jumlahHari=30;
	    }
	    if(hari<=0){
		bulan--;
		hari+=jumlahHari;
	    }
	    if(bulan<=0){
		tahun=tahun--;
		bulan+=12;
	    }

	    $('#tglLahir').attr('value',hari+'/'+bulan+'/'+tahun);
	});
	$('#tglLahir').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: 'c-50:c+10',
		onSelect: function(dateText, inst){
		    hitungUmur();
		}
	});
	$('#awal').datepicker({
		changeMonth: true,
		changeYear: true
	});
	
	$('#akhir').datepicker({
		changeMonth: true,
		changeYear: true
	});

        
	$('#tanggal').datepicker({
			changeMonth: true,
			changeYear: true
	});
        
        

});

function parseDate(str) {
  var m = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
  return (m) ? new Date(m[3], m[2]-1, m[1]) : null;
}

function isNama(str){
  var reg=/^[a-zA-Z ]+$/g;
  return reg.test(str);
}

function getCookies(c_name)
{
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
  {
      x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
      y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
      x=x.replace(/^\s+|\s+$/g,"");
      if (x==c_name)
        {
        return unescape(y);
        }
      }
}

function setCookies(c_name,value,exminutes)
{
    var exdate=new Date();
    exdate.setMinutes(exdate.getMinutes()+exminutes,0,0);
    var c_value=escape(value) + ((exminutes==null) ? "" : "; expires="+exdate.toUTCString());
    //alert(c_value+'-->'+exdate.getMinutes()+''+exminutes);
    document.cookie=c_name + "=" + c_value;
}
//Fungsi untuk periode bulanan
function isFourDigitthawal(thawal) {
if (thawal.length != 4) {
alert ("Sorry, the thawal must be four-digits in length.");
//document.form.thawal.select();
$('#thawal').select();
//document.form.thawal.focus();
$('#thawal').focus();
} else {return true;}
}
function selectDate() {
//var thawal  = document.form.thawal.value;
var thawal = $('#thawal').val();
if (isFourDigitthawal(thawal)) {
var day   = 0;
//var bln1 = document.form.bln1.selectedIndex;
var bln1 = $('#bln1').attr('selectedIndex');

        }
}

function setPreviousthawal() {
//var thawal  = document.form.thawal.value;
var thawal = $('#thawal').val();
if (isFourDigitthawal(thawal)) {
var day   = 0;
//var bln1 = document.form.bln1.selectedIndex;
var bln1 = $('#bln1').attr('selectedIndex');
thawal--;
//document.form.thawal.value = thawal;
$('#thawal').val(thawal)
   }
}
function setPreviousbln1() {
//var thawal  = document.form.thawal.value;
var thawal = $('#thawal').val();
if (isFourDigitthawal(thawal)) {
var day   = 0;
//var bln1 = document.form.bln1.selectedIndex;
var bln1 = $('#bln1').attr('selectedIndex');
if (bln1 == 0) {
bln1 = 11;
if (thawal > 1000) {
thawal--;
//document.form.thawal.value = thawal;
$('#thawal').val(thawal);
}
} else {bln1--;}
//document.form.bln1.selectedIndex = bln1;
$('#bln1').attr('selectedIndex',bln1);
}
}
function setNextbln1() {
//var thawal  = document.form.thawal.value;
var thawal = $('#thawal').val();
if (isFourDigitthawal(thawal)) {
        var day   = 0;
//        var bln1 = document.form.bln1.selectedIndex;
        var bln1 = $('#bln1').attr('selectedIndex');
        if (bln1 == 11) {
                bln1 = 0;
                thawal++;
//                document.form.thawal.value = thawal;
                $('#thawal').val(thawal);
        } else {bln1++;}
//        document.form.bln1.selectedIndex = bln1;
          $('#bln1').attr('selectedIndex',bln1)
}
}
function setNextthawal() {
//var thawal = document.form.thawal.value;
var thawal = $('#thawal').val();
if (isFourDigitthawal(thawal)) {
        var day = 0;
//        var bln1 = document.form.bln1.selectedIndex;
        var bln1 = $('#bln1').attr('selectedIndex');
        thawal++;
//        document.form.thawal.value = thawal;
        $('#thawal').val(thawal);
}
}

function getDaysInbln1(bln1,thawal)  {
var days;
if (bln1==1 || bln1==3 || bln1==5 || bln1==7 || bln1==8 || bln1==10 || bln1==12)  days=31;
else if (bln1==4 || bln1==6 || bln1==9 || bln1==11) days=30;
else if (bln1==2)  {
if (isLeapthawal(thawal)) {days=29;}
else {days=28;}
}
return (days);
}
function isFourDigitthakhir(thakhir) {
if (thakhir.length != 4) {
alert ("Sorry, the thakhir must be four-digits in length.");
//document.form.thakhir.select();
//document.form.thakhir.focus();
$('#thakhir').select();
$('#thakhir').focus();
} else {return true;}
}
function selectDate() {
//var thakhir  = document.form.thakhir.value;
var thakhir = $('#thakhir').val();
if (isFourDigitthakhir(thakhir)) {
var day   = 0;
//var bln2 = document.form.bln2.selectedIndex;
var bln2 = $('#bln2').attr('selectedIndex');
        }
}

function setPreviousthakhir() {
//var thakhir  = document.form.thakhir.value;
var thakhir = $('#thakhir').val();
if (isFourDigitthakhir(thakhir)) {
var day   = 0;
//var bln2 = document.form.bln2.selectedIndex;
var bln2 = $('#bln2').attr('selectedIndex');
thakhir--;
//document.form.thakhir.value = thakhir;
$('#thakhir').val(thakhir);
   }
}
function setPreviousbln2() {
//var thakhir  = document.form.thakhir.value;
var thakhir = $('#thakhir').val();
if (isFourDigitthakhir(thakhir)) {
var day   = 0;
//var bln2 = document.form.bln2.selectedIndex;
var bln2 = $('#bln2').attr('selectedIndex');
if (bln2 == 0) {
bln2 = 11;
if (thakhir > 1000) {
thakhir--;
//document.form.thakhir.value = thakhir;
$('#thakhir').val(thakhir);
}
} else {bln2--;}
//document.form.bln2.selectedIndex = bln2;
$('#bln2').attr('selectedIndex', bln2);
}
}
function setNextbln2() {
//var thakhir  = document.form.thakhir.value;
var thakhir = $('#thakhir').val();
if (isFourDigitthakhir(thakhir)) {
        var day   = 0;
//        var bln2 = document.form.bln2.selectedIndex;
        var bln2 = $('#bln2').attr('selectedIndex');
        if (bln2 == 11) {
                bln2 = 0;
                thakhir++;
//                document.form.thakhir.value = thakhir;
                $('#thakhir').val(thakhir);
        } else {bln2++;}
//        document.form.bln2.selectedIndex = bln2;
          $('#bln2').attr('selectedIndex', bln2);
}
}
function setNextthakhir() {
//var thakhir = document.form.thakhir.value;
var thakhir = $('#thakhir').val();
if (isFourDigitthakhir(thakhir)) {
        var day = 0;
//        var bln2 = document.form.bln2.selectedIndex;
        var bln2 = $('#bln2').attr('selectedIndex');
        thakhir++;
//        document.form.thakhir.value = thakhir;
        $('#thakhir').val(thakhir);

}
}

function getDaysInbln2(bln2,thakhir)  {
var days;
if (bln2==1 || bln2==3 || bln2==5 || bln2==7 || bln2==8 || bln2==10 || bln2==12)  days=31;
else if (bln2==4 || bln2==6 || bln2==9 || bln2==11) days=30;
else if (bln2==2)  {
if (isLeapthakhir(thakhir)) {days=29;}
else {days=28;}
}
return (days);
}
//fungsi javascript untuk periode tahunan
function isFourDigitYear(awal) {
        if (awal.length != 4) {
                alert ("Data yang dimasukkan harus integer 4 digit !");
                $('#awal').select();
                $('#awal').focus();
        } else { 
                return true; 
        }
}

function setPreviousYear() {
    var awal  = $('#awal').val();
    var akhir = $('#akhir').val();
        if (isFourDigitYear(awal)) {
                var day   = 0;
                //var month = document.form.month.selectedIndex;
                awal--;
                if (akhir < awal) {
                    $('#akhir').val(awal);	
                }
                $('#awal').val(awal);

        }
}

function setNextYear() {
        var awal  = $('#awal').val();
        var akhir = $('#akhir').val();
        if (isFourDigitYear(awal)) {
                var day = 0;
                //var month = document.form.month.selectedIndex;
                awal++;
                if (akhir < awal) {
                                $('#akhir').val(awal);
                }	
                $('#awal').val(awal);
        }
}

function isFourDigitYear(akhir) {
        if (akhir.length != 4) {
                alert ("Data yang dimasukkan harus integer 4 digit !");
                $('#akhir').select();
                $('#akhir').focus();
        } else { 
                return true; 
        }
}

function setPreviousakhir() {
        var akhir  = $('#akhir').val(); 
        var awal   = $('#awal').val();

        if (isFourDigitYear(akhir)) {
                var day   = 0;
                //var month = document.form.month.selectedIndex;
                akhir--;
                if (akhir < awal) {
                        $('#awal').val(akhir);
                }	
                $('#akhir').val(akhir);
        }
}

function setNextakhir() {
        var akhir  = $('#akhir').val(); 
        var awal   = $('#awal').val();
        if (isFourDigitYear(akhir)) {
                var day = 0;
                //var month = document.form.month.selectedIndex;
                akhir++;
                if (akhir < awal) {
                                $('#awal').val(akhir);
                }	
        $('#akhir').val(akhir);
   }
}